<?php

/**
  +----------------------------------------------------------
 * 通过分类cid生成筛选条件html 
  +----------------------------------------------------------
 * @param  [type] $cid     [分类id]
 * @param  [array] $get [属性字符串]
 * @return [type]          [html]
   +----------------------------------------------------------
 */
//加载工具类
function M($name,$data=null){
	static $classes = array();
   if (isset($classes[$name])) {
        return $classes[$name];
    }
	$file=ROOT_PLUGIN . '/jy_weishop/model/'.$name.'.php';
	require($file);
	if($data!=null){
			$classes[$name] = new $name($data);
	}else{
			$classes[$name] = new $name();
	}
	return $classes[$name];
}
//发送消息提示
function set_workerman($setmsg,$setuid,$getuid){
	$return['sign']=sha1(TIMESTAMP.$setting['cloudkey'].$_SESSION['uniacid'].$_SESSION['uid'].$setting['secret']);
	$message_pre2=$return['sign'].';'.TIMESTAMP.';'.$setting['cloudkey'].';'.$_SESSION['uniacid'].';'.$setuid.';';
	//链接tcp
	$post=array(
		'message'=>$message_pre2.$getuid.';'.$setmsg,
	);
	cloud_request('cloud.forward',$post);
	return true;
}
//接收消息提示
function get_workerman($setmsg){
	//链接tcp
	$return['sign']=sha1(TIMESTAMP.$setting['cloudkey'].$_SESSION['uniacid'].$_SESSION['uid'].$setting['secret']);
	$return['sockettcp']=$return['sign'].';'.TIMESTAMP.';'.$setting['cloudkey'].';'.$_SESSION['uniacid'].';'.$_SESSION['uid'].';0';
	$return['setmsg']=$setmsg;
	$return['mid']=$_SESSION['uid'];
	return $return;
}
function mobileProcessing($mobile = '') {
    if (!preg_match('/^1\d{10}$/' , $mobile)) {
        return $mobile;
    }
    return substr($mobile , 0 , 3) . '****' . substr($mobile , -4);
}
function plugin_set($key='setting',$data=false){
		if($data){
			$data=ijson_encode($data);
			$id=pdo_getcolumn('core_account_plugin_setting',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_weishop','key'=>$key),'id');
			if($id){
				pdo_update('core_account_plugin_setting',array('data'=>$data),array('id'=>$id));
			}else{
				pdo_insert('core_account_plugin_setting',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_weishop','key'=>$key,'data'=>$data));
			}
			return true;
		}else{
			$uniacid=$_SESSION['uniacid']?$_SESSION['uniacid']:1;
			$data=pdo_getcolumn('core_account_plugin_setting',array('uniacid'=>$uniacid,'plugin'=>'jy_weishop','key'=>$key),'data');
			if($data){
				$data=json_decode($data,true);
			}else{
				$data=array();
			}
			return $data;
		}
}
//显示广告
function show_adv($set,$setname, $width, $height, $target = NULL) 
{
	if($setname=='top'){
		if(intval($set['top_status'])==1){
		$title = ((empty($set['top_title']) ? '' : 'title=\'' . trim($set['top_title']) . '\''));
		$link = ((empty($set['top_link']) ? '' : trim($set['top_link'])));
		$width = $width;
		$height =$height;
		$src = ((empty($set['top_image']) ? '' : tomedia(trim($set['top_image']))));
		$alt = ((empty($set['top_imagedesc']) ? '' : trim($set['top_imagedesc'])));
		$target = ((empty($target) ? '' : 'target=\'_blank\''));
		echo '<a href=\'' . $link . '\' ' . $target . ' ' . $title . '><img style=\'' . $width . $height . '\' border=\'0\' src=\'' . $src . '\' alt=\'' . $alt . '\'/></a>';
		}
		else{
			return;
		}
		
	}
	elseif($setname=='logo'){
		if(intval($set['logo_status'])==1){
		$title = ((empty($set['logo_title']) ? '' : 'title=\'' . trim($set['logo_title']) . '\''));
		$link = ((empty($set['logo_link']) ? '' : trim($set['logo_link'])));
		$width = $width;
		$height =$height;
		$src = ((empty($set['logo_image']) ? '' : tomedia(trim($set['logo_image']))));
		$alt = ((empty($set['logo_imagedesc']) ? '' : trim($set['logo_imagedesc'])));
		$target = ((empty($target) ? '' : 'target=\'_blank\''));
		echo '<a href=\'' . $link . '\' ' . $target . ' ' . $title . '><img style=\'' . $width . $height . '\' border=\'0\' src=\'' . $src . '\' alt=\'' . $alt . '\'/></a>';
		}
		else{
			return;
		}
		
	}
	elseif($setname=='middle'){
		if(intval($set['logo_status'])==1){
		$title = ((empty($set['logo_title']) ? '' : 'title=\'' . trim($set['logo_title']) . '\''));
		$link = ((empty($set['logo_link']) ? '' : trim($set['logo_link'])));
		$width = $width;
		$height =$height;
		$src = ((empty($set['logo_image']) ? '' : tomedia(trim($set['logo_image']))));
		$alt = ((empty($set['logo_imagedesc']) ? '' : trim($set['logo_imagedesc'])));
		$target = ((empty($target) ? '' : 'target=\'_blank\''));
		echo '<a href=\'' . $link . '\' ' . $target . ' ' . $title . '><img style=\'' . $width . $height . '\' border=\'0\' src=\'' . $src . '\' alt=\'' . $alt . '\'/></a>';
		}
		else{
			return;
		}
		
	}
	elseif($setname=='right'){
		if(intval($set['right_status'])==1){
		$title = ((empty($set['right_title']) ? '' : 'title=\'' . trim($set['right_title']) . '\''));
		$link = ((empty($set['right_link']) ? '' : trim($set['right_link'])));
		$width = $width;
		$height =$height;
		$src = ((empty($set['right_image']) ? '' : tomedia(trim($set['right_image']))));
		$alt = ((empty($set['right_imagedesc']) ? '' : trim($set['right_imagedesc'])));
		$target = ((empty($target) ? '' : 'target=\'_blank\''));
		echo '<a href=\'' . $link . '\' ' . $target . ' ' . $title . '><img style=\'' . $width . $height . '\' border=\'0\' src=\'' . $src . '\' alt=\'' . $alt . '\'/></a>';
		}
		else{
			return;
		}
		
	}
	elseif($setname=='bottom'){
		if(intval($set['bottom_status'])==1){
		$title = ((empty($set['bottom_title']) ? '' : 'title=\'' . trim($set['bottom_title']) . '\''));
		$link = ((empty($set['bottom_link']) ? '' : trim($set['bottom_link'])));
		$width = $width;
		$height =$height;
		$src = ((empty($set['bottom_image']) ? '' : tomedia(trim($set['bottom_image']))));
		$alt = ((empty($set['bottom_imagedesc']) ? '' : trim($set['bottom_imagedesc'])));
		$target = ((empty($target) ? '' : 'target=\'_blank\''));
		echo '<a href=\'' . $link . '\' ' . $target . ' ' . $title . '><img style=\'' . $width . $height . '\' border=\'0\' src=\'' . $src . '\' alt=\'' . $alt . '\'/></a>';
		}
		else{
			return;
		}
		
	}
		
	
}
?>
